//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "StringUtilities.h"

void TStringUtilites :: Clear( TStrings * list)
{
   int i;
   int count = list->Count;

   for ( i = 0; i < count; i++)
   {
      delete list->Objects[ i];
   }//for

   list->Clear();
}

int TStringUtilites :: FindBestMatch( TStrings * list, AnsiString key)
{
   AnsiString bestMatchKey = key;
   int keysCount = list->Count;
   bool found = false;
   int index = -1;

   while((bestMatchKey.Length() != 0) && (!found))
   {
      int i = 0;
      while((i < keysCount) && (!found))
      {
         AnsiString currKey = (*list)[i];
         found = (currKey.Pos(key) == 1);
         if (found)
            index = i;
         else
         {
            i++;
         }
      }//while

      if (!found)
      {
         bestMatchKey.Delete(bestMatchKey.Length(), 1);
      }
   }//while

   return index;
}

AnsiString TStringUtilites :: BooleanToYN( bool flag)
{
   if ( flag)
      return "Y";
   return "N";   
}

bool TStringUtilites :: YNToBoolean( AnsiString yn)
{
   return ( yn == "Y");
}


//---------------------------------------------------------------------------

#pragma package(smart_init)
